<template>
	<view>
		<view class="box">
			<view class="mlr-36 mt-20 plr-36 bg-white radius-10">
				<view class="pt-30 ml-4">
					紧急联系人姓名
				</view>
				<view style="height: 20rpx;"></view>
				<view style="width: 95%;height: 80rpx;background-color: #F6F7FB;border-radius: 20rpx;margin: auto;">
					<input v-model="name" style="width: 80%;height: 80rpx;margin-left: 20rpx;" type="text">
				</view>
				
				<view class="pt-30 ml-4">
					紧急联系人手机号码
				</view>
				<view style="height: 20rpx;"></view>
				<view style="width: 95%;height: 80rpx;background-color: #F6F7FB;border-radius: 20rpx;margin: auto;">
					<input v-model="tel" style="width: 80%;height: 80rpx;margin-left: 20rpx;" type="number">
				</view>
				<view style="height: 20rpx;"></view>
			</view>
			<view class="plr-36 ptb-50">
				<u-button v-if="id" type="primary" :disabled="!tel || !name" @click="upd">修改</u-button>
				<u-button v-else type="primary" :disabled="!tel || !name" @click="submit">保存</u-button>
				<view style="height: 50rpx;"></view>
				<u-button v-if="id" type="primary" @click="del">删除</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:'',
				tel:'',
				id:''
			}
		},
		onLoad(op) {
			console.log(op,'opopopop')
			this.id = op.item
		},
		methods: {
			submit(){
				this.$http('user/addClossUser',{
					name: this.name,
					mobile: this.tel
				},"POST").then(data=>{
					console.log(data);
					this.$store.dispatch('updateUserInfo')
					uni.showToast({
						title: '添加成功'
					})
					setTimeout(() => {
						uni.navigateBack({})
					}, 500)
				})
			},
			upd(){
				this.$http('user/updClossUser',{
					id:this.id,
					name: this.name,
					mobile: this.tel
				},"POST").then(data=>{
					console.log(data);
					uni.showToast({
						title: '修改成功'
					})
					// setTimeout(() => {
					// 	uni.navigateBack({})
					// }, 500)
				})
			},
			del(){
				this.$http('user/delClossUser',{
					id:this.id
				},"POST").then(data=>{
					// this.$store.dispatch('updateUserInfo')
					uni.navigateBack({})
					// uni.showToast({
					// 	title: '删除成功'
					// })
					// setTimeout(() => {
					// 	uni.navigateBack({})
					// }, 500)
				})
			}
		}
	}
</script>

<style lang="scss">
	.box {
		width: 100%;
		height: 100vh;
		background: #F8F8F8;
		overflow: hidden;
	}
	/deep/.u-btn {
		height: 96rpx !important;
	}
	
	/deep/.u-primary-hover {
		background-color: $blue !important;
	}
	
	/deep/.u-btn--primary--disabled {
		background-color: $bg-1 !important;
	}
</style>
